#!/bin/sh
# Script to package up a release of Freebench.
if [ ! -f "version.py" ]; then
  echo "could not find version.py in current directory"
  exit 2
fi

version=`grep VERSION version.py | cut -d\' -f2 | cut -d- -f1`
dist_name="freebench-$version"
dist_file="${dist_name}.tar.gz"
base_dir="/tmp"
dir="$base_dir/$dist_name"

echo "Packaging Freebench $version into $dir"
rm $base_dir/$dist_file 2>/dev/null
rm -Rf $dir
mkdir -p $dir
svn update
svn log  > $dir/CHANGELOG
cp freebench *.py *.yml README LICENSE $dir
cp -Rp data yaml tools $dir
mkdir -p $dir/build $dir/test $dir/distfiles
find $dir -name ".svn" -exec rm -Rf {} \;
find $dir -name "*.pyc" -exec rm {} \;
find $dir -name '*~' -exec rm {} \;
sed s/"-DEVELOPMENT"/""/g version.py > $dir/version.py
find $dir -name '.*' -type f -exec rm {} \;
find $dir -type f -exec chmod 444 {} \;
find $dir -type d -exec chmod 755 {} \;
chmod 755 $dir/freebench tools/*sh sysinfo.py

# For Mac OS X to not inject silly dot files.
export COPYFILE_DISABLE=true
echo "Archiving: cd $base_dir && tar -zcvf $dist_file $dist_name"
cd $base_dir && tar -zcvf $dist_file $dist_name
ls -la $base_dir/$dist_file
